package com.settlement.system.service.impl;

import com.settlement.system.model.entity.NotLinkNoRecord;
import com.settlement.system.mapper.NotLinkNoRecordMapper;
import com.settlement.system.service.NotLinkNoRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.util.Assert;
import com.settlement.system.common.util.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.settlement.system.model.query.NotLinkNoRecordQuery;
import com.settlement.system.model.form.NotLinkNoRecordForm;
import org.springframework.beans.BeanUtils;
import com.settlement.system.model.vo.NotLinkNoRecordImportVo;

/**
 * <p>
 * 没有关联单号的标准账单表 服务实现类
 * </p>
 *
 * @author huangrensen
 * @since 2024-07-10
 */
@Service
public class NotLinkNoRecordServiceImpl extends ServiceImpl<NotLinkNoRecordMapper, NotLinkNoRecord> implements NotLinkNoRecordService {

    @Override
    public Page<NotLinkNoRecord> getPage(NotLinkNoRecordQuery queryParams) {
        // 查询参数
        int pageNum = queryParams.getPageNum();
        int pageSize = queryParams.getPageSize();
        // 查询数据
        Page<NotLinkNoRecord> page = new Page<>(pageNum, pageSize);
        return this.baseMapper.getPage(page, queryParams);
    }

     @Override
     public boolean saveNotLinkNoRecord(NotLinkNoRecordForm notLinkNoRecordForm) {
         NotLinkNoRecord notLinkNoRecord = new NotLinkNoRecord();
         BeanUtils.copyProperties(notLinkNoRecordForm, notLinkNoRecord);
         return this.saveOrUpdate(notLinkNoRecord);
     }

     @Override
     public NotLinkNoRecordForm getNotLinkNoRecordFormData(Long id) {
         NotLinkNoRecord notLinkNoRecord = this.getById(id);
         NotLinkNoRecordForm notLinkNoRecordForm = new NotLinkNoRecordForm();
         BeanUtils.copyProperties(notLinkNoRecord, notLinkNoRecordForm);
         return notLinkNoRecordForm;
     }

     @Override
     public boolean deleteNotLinkNoRecord(String ids) {
        Assert.isTrue(StringUtils.hasText(ids), "删除的数据为空");
        List<Long> idArray = Arrays.stream(ids.split(",")).map(Long::parseLong).collect(Collectors.toList());
        return this.removeByIds(idArray);
     }

    @Override
    public void importData(List<NotLinkNoRecordImportVo> voList)  {
        List<NotLinkNoRecord> notLinkNoRecordList = new ArrayList<>();
        for (NotLinkNoRecordImportVo importVo : voList) {
            NotLinkNoRecord notLinkNoRecord = new NotLinkNoRecord();
            BeanUtils.copyProperties(importVo, notLinkNoRecord);
            notLinkNoRecordList.add(notLinkNoRecord);
        }
        this.saveOrUpdateBatch(notLinkNoRecordList);
    }

    @Override
    public List<NotLinkNoRecordImportVo> findByIds(String idsStr) {
        if (!StringUtils.hasText(idsStr)) {
            return new ArrayList<>();
        }
        List<Long> ids = Arrays.stream(idsStr.split(",")).map(Long::parseLong).collect(Collectors.toList());
        List<NotLinkNoRecord> notLinkNoRecordList = this.getBaseMapper().selectBatchIds(ids);
        List<NotLinkNoRecordImportVo> voList = new ArrayList<>();
        for (NotLinkNoRecord notLinkNoRecord : notLinkNoRecordList) {
            NotLinkNoRecordImportVo vo = new NotLinkNoRecordImportVo();
            BeanUtils.copyProperties(notLinkNoRecord, vo);
            voList.add(vo);
        }
        return voList;
    }
}
